package com.siyuanren.gcocp.web.wx;

import cn.hutool.core.codec.Base64;
import com.siyuanren.gcocp.common.config.PublicConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.UUID;

/**
 * @author guwr
 */
@Slf4j
@RequestMapping("")
@Controller
public class WxIndexController {
    @GetMapping({"/", "index"})
    public String index(Model model) {
        log.info("index html come in");
        return "redirect:" + PublicConfig.PUBLIC_WX_URL;
    }

    @RequestMapping("error")
    public String error(Model model) {
        return "redirect:error.html";
    }

    /**
     * 用于外部链接.跳转如小课. vue无法处理微信登录问题. 使用方法先验证登录,在跳转到需要访问的链接
     * @param model
     * @param actualUrl   真正需要访问的链接. 使用base64 加密
     * @return
     */
    @RequestMapping("/authAndGo")
    public String authAndGo(Model model, String actualUrl) {
        return "redirect:" + PublicConfig.PUBLIC_WX_URL + Base64.decodeStr(actualUrl);
    }
}
